package com.carter.springframework.context.support;

import com.carter.springframework.beans.exception.BeanException;
import com.carter.springframework.beans.factory.ConfigurableListableBeanFactory;
import com.carter.springframework.beans.factory.config.DefaultSingletonBeanRegistry;
import com.carter.springframework.beans.factory.support.DefaultListableBeanFactory;

/**
 * 实现了父类的刷新bean工厂的方法以及获取bean工厂的方法
 */
public abstract class AbstractRefreshableApplicationContext extends AbstractApplicationContext {
    private DefaultListableBeanFactory beanFactory;

    @Override
    protected void refreshBeanFactory() throws BeanException {
        DefaultListableBeanFactory defaultListableBeanFactory = new DefaultListableBeanFactory();
        //读取beanDefinition
        loadBeanDefinitions(defaultListableBeanFactory);
        this.beanFactory = defaultListableBeanFactory;
    }

    /**
     * 读取beanDefinition
     * @param defaultListableBeanFactory
     */
    protected abstract void loadBeanDefinitions(DefaultListableBeanFactory defaultListableBeanFactory);

    @Override
    public ConfigurableListableBeanFactory getBeanFactory(){
        return beanFactory;
    }
}
